package com.ruoyi.project.module.jingdian.controller;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.module.userinfo.domain.Userinfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.jingdian.domain.Jingdian;
import com.ruoyi.project.module.jingdian.service.IJingdianService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 景点介绍 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-12
 */
@Controller
@RequestMapping("/module/jingdian")
public class JingdianController extends BaseController
{
    private String prefix = "module/jingdian";
	
	@Autowired
	private IJingdianService jingdianService;
	
	@RequiresPermissions("module:jingdian:view")
	@GetMapping()
	public String jingdian()
	{
	    return prefix + "/jingdian";
	}
	
	/**
	 * 查询景点介绍列表
	 */
	@RequiresPermissions("module:jingdian:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Jingdian jingdian)
	{
		startPage();
        List<Jingdian> list = jingdianService.selectJingdianList(jingdian);
		return getDataTable(list);
	}
	/**
	 * 导出景点信息
	 */

	@Log(title = "景点", businessType = BusinessType.EXPORT)
	@RequiresPermissions("system:jingdian:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Jingdian jingdian) throws Exception
	{
		try
		{
			List<Jingdian> list = jingdianService.selectJingdianList(jingdian);
			ExcelUtil<Jingdian> util = new ExcelUtil<Jingdian>(Jingdian.class);
			return util.exportExcel(list, "jingdian");
		}
		catch (Exception e)
		{
			return error("导出Excel失败，请联系网站管理员！");
		}
	}
	/**
	 * 新增景点介绍
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存景点介绍
	 */
	@RequiresPermissions("module:jingdian:add")
	@Log(title = "景点介绍", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Jingdian jingdian)
	{		
		return toAjax(jingdianService.insertJingdian(jingdian));
	}

	/**
	 * 修改景点介绍
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Integer userId, ModelMap mmap)
	{
		Jingdian jingdian = jingdianService.selectJingdianById(userId);
		mmap.put("jingdian", jingdian);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存景点介绍
	 */
	@RequiresPermissions("module:jingdian:edit")
	@Log(title = "景点介绍", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Jingdian jingdian)
	{		
		return toAjax(jingdianService.updateJingdian(jingdian));
	}
	
	/**
	 * 删除景点介绍
	 */
	@RequiresPermissions("module:jingdian:remove")
	@Log(title = "景点介绍", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(jingdianService.deleteJingdianByIds(ids));
	}
	
}
